home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / printing / rlpr-1.000 / rlpr-1 / rlpr-1.13 / rlpr-common.c < prev    next >
C/C++ Source or Header  |  1996-06-30  |  2KB  |  78 lines

  1. /* filename: rlpr-common.c
  2.  * project: rlpr
  3.  * author: meem  --  meem@sherilyn.wustl.edu
  4.  * version: $Id: rlpr-common.c,v 1.6 1996/07/01 01:07:53 meem Exp $
  5.  * contents: general-purpose functions for rlpr
  6.  *
  7.  * Time-stamp: <1996/06/30 20:17 -- meem@sherilyn>
  8.  */
  9.  
  10. /* copyright (c) 1996 meem, meem@gnu.ai.mit.edu
  11.  *
  12.  * This program is free software; you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation; either version 1, or (at your option)
  15.  * any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20.  * General Public License for more details.
  21.  */
  22.  
  23. #include <stdio.h>
  24. #include <string.h>        /* for strerror() */
  25. #include <ctype.h>
  26. #include <sys/stat.h>        /* for fstat()   */
  27. #include <sys/utsname.h>    /* for uname()   */
  28. #include <unistd.h>        /* for fstat()   */
  29. #include <stdarg.h>        /* for varargs   */
  30. #include "rlpr-common.h"
  31.  
  32. void rlpr_fatal(char *fmt, ...) {
  33.   va_list ap;
  34.   fprintf(stderr, "%s: fatal: ", name);
  35.   va_start(ap, fmt);
  36.   vfprintf(stderr, fmt, ap);
  37.   fputc('\n', stderr);
  38.   va_end(ap);
  39.   exit(1);
  40. }
  41.  
  42. void rlpr_warn(char *fmt, ...) {
  43.   va_list ap;
  44.   if (opts_.qflag) return;
  45.   fprintf(stderr, "%s: warning: ", name);
  46.   va_start(ap, fmt);
  47.   vfprintf(stderr, fmt, ap);
  48.   fputc('\n', stderr);
  49.   va_end(ap);
  50. }
  51.  
  52. void get_local_hostname(void) {
  53.   struct utsname buf;
  54.   if (uname(&buf) < 0)
  55.     rlpr_fatal("unable to resolve your local hostname!");
  56.   else {
  57.     if (strlen(buf.nodename) > MAXHOSTNAMELEN)
  58.       rlpr_fatal("your hostname is horribly long or hosed!");
  59.     else strcpy(local_hostname, buf.nodename);
  60.   }
  61. }
  62.  
  63. void strlower(char *str) {
  64.   while ((*str++ = tolower(*str)));
  65. }  
  66.  
  67. /* this works with an fd because it is used with temporary
  68.  * files that have already been unlink()'ed.
  69.  */
  70.  
  71. off_t filesz(int fd) {
  72.   struct stat st;
  73.  
  74.   if (fstat(fd, &st) < 0)
  75.     rlpr_fatal("fd %i: %s, make sure /tmp is writable!", fd, ERRNO);
  76.   return st.st_size;
  77. }
  78.